home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / WINPROGS / SPHERES.ZIP / TSCRNSAV.CPP < prev    next >
C/C++ Source or Header  |  1993-06-25  |  4KB  |  163 lines

  1. // ObjectWindows - (C) Copyright 1992 by Borland International
  2. //
  3. // tscrnsav.cpp
  4. //
  5. // Modified by Philip VanBaren (71214,2302 or phillipv@engin.umich.edu)
  6. // to enable the screen saver to work with NDW's Sleeper program.  
  7. //
  8. // The main modifications are:
  9. //   1) Window class is "WindowsScreenSaverClass"  (this is required for the
  10. //        saver to work properly with Sleeper.
  11. //   2) IdleAction does screen saver things on only 1 out of 100 calls,
  12. //        thereby allowing background events (backups, printing, etc.) to  
  13. //        retain most of the processing power when they need it.
  14. //   3) "-c", "/c", "c", "-s", "/s", "s", and "" are accepted as valid command
  15. //        line parameters.  (Sleeper passes "c" and "-s" to start the configure
  16. //        and saver routines, respectively.)
  17. //   4) Allow some slop in mouse movement before aborting the screen saver,
  18. //        so that the screen saver doesn't abort whenever the desk is bumped.
  19.  
  20. #include <owl.h>
  21. #include <ctype.h>
  22. #include "tscrnsav.h"
  23.  
  24. #ifndef SC_SCREENSAVE
  25. #define SC_SCREENSAVE 0xF140
  26. #endif
  27.  
  28. TScrnSavWindow::TScrnSavWindow( PTWindowsObject AParent, LPSTR ATitle,
  29.                                 PTModule AModule ) :
  30.                 TWindow( AParent, ATitle, AModule )
  31. {
  32.     /*
  33.      *  Hide the cursor.
  34.      */
  35.     while(ShowCursor( FALSE ) >= 0);
  36.     Attr.Style  = WS_POPUP;
  37. }
  38.  
  39.  
  40. TScrnSavWindow::~TScrnSavWindow()
  41. {
  42.     ShowCursor( TRUE );
  43. }
  44.  
  45. void TScrnSavWindow::GetWindowClass( WNDCLASS & AWndClass )
  46. {
  47.     TWindow::GetWindowClass( AWndClass );
  48.     AWndClass.hIcon  = ( HICON )NULL;
  49.     AWndClass.style |= CS_SAVEBITS;
  50.     AWndClass.hbrBackground = ( HBRUSH )GetStockObject( NULL_BRUSH );
  51. }
  52.  
  53.  
  54. void TScrnSavWindow::SetupWindow( void )
  55. {
  56.     RECT rc;
  57.  
  58.     TWindow::SetupWindow();
  59.     GetCursorPos( &prevPt );
  60.     GetWindowRect( GetDesktopWindow(), &rc );
  61.     MoveWindow( HWindow, rc.left, rc.top, rc.right, rc.bottom, TRUE );
  62. }
  63.  
  64.  
  65. void TScrnSavWindow::DefWndProc( RTMessage msg )
  66. {
  67.     switch( msg.Message )
  68.     {
  69.         case WM_MOUSEMOVE:
  70.              /*
  71.               *  If the mouse moves more than 10 pixels,
  72.               *  abort the screen saver.
  73.               *  This allows for some slop so that bumping the desk
  74.               *  will not abort the screen saver.
  75.               */
  76.              if ( (abs(MAKEPOINT( msg.LParam ).x-prevPt.x)
  77.                   +abs(MAKEPOINT( msg.LParam ).y-prevPt.y)) < 10 )
  78.                  break;
  79.  
  80.         case WM_ACTIVATE:
  81.         case WM_ACTIVATEAPP:
  82.              if ( msg.WParam != 0 )
  83.                  break;
  84.  
  85.         case WM_KEYDOWN:
  86.         case WM_SYSKEYDOWN:
  87.         case WM_LBUTTONDOWN:
  88.         case WM_MBUTTONDOWN:
  89.         case WM_RBUTTONDOWN:
  90.              PostMessage( HWindow, WM_CLOSE, 0, 0L );
  91.  
  92.         default:
  93.              break;
  94.     }
  95.     TWindow::DefWndProc( msg );
  96. }
  97.  
  98.  
  99. void TScrnSavWindow::WMSysCommand( RTMessage msg )
  100. {
  101.    if (( msg.WParam & 0xFFF0 ) == SC_SCREENSAVE )
  102.    {
  103.       msg.Result = TRUE;
  104.    }
  105.    else
  106.       DefWndProc( msg );
  107. }
  108.  
  109.  
  110. void TScrnSavWindow::AnimateScreen()
  111. {}
  112.  
  113.  
  114.  
  115. void TScrnSavApp::InitMainWindow()
  116. {
  117.    int cmdswitch;
  118.  
  119.    cmdswitch=toupper(lpCmdLine[0]);
  120.    if((cmdswitch == '/') || (cmdswitch == '-'))
  121.       cmdswitch=toupper(lpCmdLine[1]);
  122.  
  123.    if(cmdswitch == 'S')
  124.    {
  125.       fConfigureFlag = FALSE;
  126.       InitScrnSavWindow();
  127.       if ( pScrnSavWnd )
  128.          MainWindow = pScrnSavWnd;
  129.    }
  130.    else
  131.    {
  132.       fConfigureFlag = TRUE;
  133.       InitConfigDialog();
  134.       if ( pConfigureDialog )
  135.          MainWindow = pConfigureDialog;
  136.    }
  137. }
  138.  
  139.  
  140. void TScrnSavApp::InitScrnSavWindow()
  141. {
  142.     pScrnSavWnd = new TScrnSavWindow( NULL, NULL, NULL );
  143.     j=0;
  144. }
  145.  
  146.  
  147. void TScrnSavApp::IdleAction()
  148. {
  149.    if ( fConfigureFlag == FALSE  &&  pScrnSavWnd != NULL )
  150.    {
  151.       /*
  152.        *  Only allow screen saver to use 1% of available time so that
  153.        *  background processing (such as printing) is not slowed down.
  154.        */
  155.       j++;
  156.       if(j>100)
  157.       {
  158.          pScrnSavWnd->AnimateScreen();
  159.          j=0;
  160.       }
  161.    }
  162. }
  163.